home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_db.idb / usr / freeware / include / db.h.z / db.h
Encoding:
C/C++ Source or Header  |  1999-04-16  |  36.9 KB  |  1,049 lines

  1. /*-
  2.  * See the file LICENSE for redistribution information.
  3.  *
  4.  * Copyright (c) 1996, 1997, 1998
  5.  *    Sleepycat Software.  All rights reserved.
  6.  *
  7.  *    @(#)db.h    10.174 (Sleepycat) 1/3/99
  8.  */
  9.  
  10. #ifndef _DB_H_
  11. #define    _DB_H_
  12.  
  13. #ifndef __NO_SYSTEM_INCLUDES
  14. #include <sys/types.h>
  15.  
  16. #include <stdio.h>
  17. #endif
  18.  
  19. /*
  20.  * XXX
  21.  * MacOS: ensure that Metrowerks C makes enumeration types int sized.
  22.  */
  23. #ifdef __MWERKS__
  24. #pragma enumsalwaysint on
  25. #endif
  26.  
  27. /*
  28.  * XXX
  29.  * Handle function prototypes and the keyword "const".  This steps on name
  30.  * space that DB doesn't control, but all of the other solutions are worse.
  31.  *
  32.  * XXX
  33.  * While Microsoft's compiler is ANSI C compliant, it doesn't have _STDC_
  34.  * defined by default, you specify a command line flag or #pragma to turn
  35.  * it on.  Don't do that, however, because some of Microsoft's own header
  36.  * files won't compile.
  37.  */
  38. #undef    __P
  39. #if defined(__STDC__) || defined(__cplusplus) || defined(_MSC_VER)
  40. #define    __P(protos)    protos        /* ANSI C prototypes */
  41. #else
  42. #define    const
  43. #define    __P(protos)    ()        /* K&R C preprocessor */
  44. #endif
  45.  
  46. /*
  47.  * !!!
  48.  * DB needs basic information about specifically sized types.  If they're
  49.  * not provided by the system, typedef them here.
  50.  *
  51.  * We protect them against multiple inclusion using __BIT_TYPES_DEFINED__,
  52.  * as does BIND and Kerberos, since we don't know for sure what #include
  53.  * files the user is using.
  54.  *
  55.  * !!!
  56.  * We also provide the standard u_int, u_long etc., if they're not provided
  57.  * by the system.
  58.  */
  59. #ifndef    __BIT_TYPES_DEFINED__
  60. #define    __BIT_TYPES_DEFINED__
  61.  
  62.  
  63.  
  64.  
  65.  
  66. #endif
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73. #define    DB_VERSION_MAJOR    2
  74. #define    DB_VERSION_MINOR    7
  75. #define    DB_VERSION_PATCH    3
  76. #define    DB_VERSION_STRING    "Sleepycat Software: Berkeley DB 2.7.3: (02/04/99)"
  77.  
  78. typedef    u_int32_t    db_pgno_t;    /* Page number type. */
  79. typedef    u_int16_t    db_indx_t;    /* Page offset type. */
  80. #define    DB_MAX_PAGES    0xffffffff    /* >= # of pages in a file */
  81.  
  82. typedef    u_int32_t    db_recno_t;    /* Record number type. */
  83. #define    DB_MAX_RECORDS    0xffffffff    /* >= # of records in a tree */
  84.  
  85. typedef size_t        DB_LOCK;    /* Object returned by lock manager. */
  86.  
  87. /* Forward structure declarations, so applications get type checking. */
  88. struct __db;        typedef struct __db DB;
  89. #ifdef DB_DBM_HSEARCH
  90.             typedef struct __db DBM;
  91. #endif
  92. struct __db_bt_stat;    typedef struct __db_bt_stat DB_BTREE_STAT;
  93. struct __db_dbt;    typedef struct __db_dbt DBT;
  94. struct __db_env;    typedef struct __db_env DB_ENV;
  95. struct __db_ilock;    typedef struct __db_ilock DB_LOCK_ILOCK;
  96. struct __db_info;    typedef struct __db_info DB_INFO;
  97. struct __db_lock_stat;    typedef struct __db_lock_stat DB_LOCK_STAT;
  98. struct __db_lockregion;    typedef struct __db_lockregion DB_LOCKREGION;
  99. struct __db_lockreq;    typedef struct __db_lockreq DB_LOCKREQ;
  100. struct __db_locktab;    typedef struct __db_locktab DB_LOCKTAB;
  101. struct __db_log;    typedef struct __db_log DB_LOG;
  102. struct __db_log_stat;    typedef struct __db_log_stat DB_LOG_STAT;
  103. struct __db_lsn;    typedef struct __db_lsn DB_LSN;
  104. struct __db_mpool;    typedef struct __db_mpool DB_MPOOL;
  105. struct __db_mpool_finfo;typedef struct __db_mpool_finfo DB_MPOOL_FINFO;
  106. struct __db_mpool_fstat;typedef struct __db_mpool_fstat DB_MPOOL_FSTAT;
  107. struct __db_mpool_stat;    typedef struct __db_mpool_stat DB_MPOOL_STAT;
  108. struct __db_mpoolfile;    typedef struct __db_mpoolfile DB_MPOOLFILE;
  109. struct __db_txn;    typedef struct __db_txn DB_TXN;
  110. struct __db_txn_active;    typedef struct __db_txn_active DB_TXN_ACTIVE;
  111. struct __db_txn_stat;    typedef struct __db_txn_stat DB_TXN_STAT;
  112. struct __db_txnmgr;    typedef struct __db_txnmgr DB_TXNMGR;
  113. struct __db_txnregion;    typedef struct __db_txnregion DB_TXNREGION;
  114. struct __dbc;        typedef struct __dbc DBC;
  115.  
  116. /* Key/data structure -- a Data-Base Thang. */
  117. struct __db_dbt {
  118.     void     *data;            /* key/data */
  119.     u_int32_t size;            /* key/data length */
  120.     u_int32_t ulen;            /* RO: length of user buffer. */
  121.     u_int32_t dlen;            /* RO: get/put record length. */
  122.     u_int32_t doff;            /* RO: get/put record offset. */
  123.  
  124. #define    DB_DBT_INTERNAL    0x01        /* Ignore user's malloc (internal). */
  125. #define    DB_DBT_MALLOC    0x02        /* Return in allocated memory. */
  126. #define    DB_DBT_PARTIAL    0x04        /* Partial put/get. */
  127. #define    DB_DBT_USERMEM    0x08        /* Return in user's memory. */
  128.     u_int32_t flags;
  129. };
  130.  
  131. /*
  132.  * DB run-time interface configuration.
  133.  *
  134.  * There are a set of functions that the application can replace with its
  135.  * own versions, and some other knobs which can be turned at run-time.
  136.  */
  137. #define    DB_FUNC_CLOSE     1        /* POSIX 1003.1 close. */
  138. #define    DB_FUNC_DIRFREE     2        /* DB: free directory list. */
  139. #define    DB_FUNC_DIRLIST     3        /* DB: create directory list. */
  140. #define    DB_FUNC_EXISTS     4        /* DB: return if file exists. */
  141. #define    DB_FUNC_FREE     5        /* ANSI C free. */
  142. #define    DB_FUNC_FSYNC     6        /* POSIX 1003.1 fsync. */
  143. #define    DB_FUNC_IOINFO     7        /* DB: return file I/O information. */
  144. #define    DB_FUNC_MALLOC     8        /* ANSI C malloc. */
  145. #define    DB_FUNC_MAP     9        /* DB: map file into shared memory. */
  146. #define    DB_FUNC_OPEN    10        /* POSIX 1003.1 open. */
  147. #define    DB_FUNC_READ    11        /* POSIX 1003.1 read. */
  148. #define    DB_FUNC_REALLOC    12        /* ANSI C realloc. */
  149. #define    DB_FUNC_RUNLINK    13        /* DB: remove a shared region. */
  150. #define    DB_FUNC_SEEK    14        /* POSIX 1003.1 lseek. */
  151. #define    DB_FUNC_SLEEP    15        /* DB: sleep secs/usecs. */
  152. #define    DB_FUNC_UNLINK    16        /* POSIX 1003.1 unlink. */
  153. #define    DB_FUNC_UNMAP    17        /* DB: unmap shared memory file. */
  154. #define    DB_FUNC_WRITE    18        /* POSIX 1003.1 write. */
  155. #define    DB_FUNC_YIELD    19        /* DB: yield thread to scheduler. */
  156. #define    DB_MUTEXLOCKS    20        /* DB: turn off all mutex locks. */
  157. #define    DB_PAGEYIELD    21        /* DB: yield the CPU on pool get. */
  158. #define    DB_REGION_ANON    22        /* DB: anonymous, unnamed regions. */
  159. #define    DB_REGION_INIT    23        /* DB: page-fault regions in create. */
  160. #define    DB_REGION_NAME    24        /* DB: anonymous, named regions. */
  161. #define    DB_TSL_SPINS    25        /* DB: initialize spin count. */
  162.  
  163. /*
  164.  * Database configuration and initialization.
  165.  */
  166.  /*
  167.   * Flags understood by both db_open(3) and db_appinit(3).
  168.   */
  169. #define    DB_CREATE          0x000001    /* O_CREAT: create file as necessary. */
  170. #define    DB_NOMMAP          0x000002    /* Don't mmap underlying file. */
  171. #define    DB_THREAD          0x000004    /* Free-thread DB package handles. */
  172.  
  173. /*
  174.  * Flags understood by db_appinit(3).
  175.  */
  176. /*                  0x000007       COMMON MASK. */
  177. #define    DB_INIT_CDB          0x000008    /* Concurrent Access Methods. */
  178. #define    DB_INIT_LOCK          0x000010    /* Initialize locking. */
  179. #define    DB_INIT_LOG          0x000020    /* Initialize logging. */
  180. #define    DB_INIT_MPOOL          0x000040    /* Initialize mpool. */
  181. #define    DB_INIT_TXN          0x000080    /* Initialize transactions. */
  182. #define    DB_MPOOL_PRIVATE      0x000100    /* Mpool: private memory pool. */
  183. #define    DB_RECOVER          0x000200    /* Run normal recovery. */
  184. #define    DB_RECOVER_FATAL      0x000400    /* Run catastrophic recovery. */
  185. #define    DB_TXN_NOSYNC          0x000800    /* Do not sync log on commit. */
  186. #define    DB_USE_ENVIRON          0x001000    /* Use the environment. */
  187. #define    DB_USE_ENVIRON_ROOT   0x002000    /* Use the environment if root. */
  188.  
  189. /*
  190.  * Flags understood by db_open(3).
  191.  *
  192.  * DB_EXCL and DB_TEMPORARY are internal only, and are not documented.
  193.  * DB_SEQUENTIAL is currently internal, but may be exported some day.
  194.  */
  195. /*                  0x000007       COMMON MASK. */
  196. /*                  0x001fff       ALREADY USED. */
  197. #define    DB_EXCL              0x002000    /* O_EXCL: exclusive open (internal). */
  198. #define    DB_RDONLY          0x004000    /* O_RDONLY: read-only. */
  199. #define    DB_SEQUENTIAL          0x008000    /* Sequential access (internal). */
  200. #define    DB_TEMPORARY          0x010000    /* Remove on last close (internal). */
  201. #define    DB_TRUNCATE          0x020000    /* O_TRUNCATE: replace existing DB. */
  202.  
  203. /*
  204.  * Deadlock detector modes; used in the DBENV structure to configure the
  205.  * locking subsystem.
  206.  */
  207. #define    DB_LOCK_NORUN        0
  208. #define    DB_LOCK_DEFAULT        1    /* Default policy. */
  209. #define    DB_LOCK_OLDEST        2    /* Abort oldest transaction. */
  210. #define    DB_LOCK_RANDOM        3    /* Abort random transaction. */
  211. #define    DB_LOCK_YOUNGEST    4    /* Abort youngest transaction. */
  212.  
  213. struct __db_env {
  214.     int         db_lorder;    /* Byte order. */
  215.  
  216.                     /* Error message callback. */
  217.     void (*db_errcall) __P((const char *, char *));
  218.     FILE        *db_errfile;    /* Error message file stream. */
  219.     const char    *db_errpfx;    /* Error message prefix. */
  220.     int         db_verbose;    /* Generate debugging messages. */
  221.     int         db_panic;    /* Panic flag, callback function. */
  222.     void (*db_paniccall) __P((DB_ENV *, int));
  223.  
  224.     /* User paths. */
  225.     char        *db_home;    /* Database home. */
  226.     char        *db_log_dir;    /* Database log file directory. */
  227.     char        *db_tmp_dir;    /* Database tmp file directory. */
  228.  
  229.     char           **db_data_dir;    /* Database data file directories. */
  230.     int         data_cnt;    /* Database data file slots. */
  231.     int         data_next;    /* Next Database data file slot. */
  232.  
  233.     /* Locking. */
  234.     DB_LOCKTAB    *lk_info;    /* Return from lock_open(). */
  235.     const u_int8_t    *lk_conflicts;    /* Two dimensional conflict matrix. */
  236.     u_int32_t     lk_modes;    /* Number of lock modes in table. */
  237.     u_int32_t     lk_max;    /* Maximum number of locks. */
  238.     u_int32_t     lk_detect;    /* Deadlock detect on all conflicts. */
  239.  
  240.     /* Logging. */
  241.     DB_LOG        *lg_info;    /* Return from log_open(). */
  242.     u_int32_t     lg_max;    /* Maximum file size. */
  243.  
  244.     /* Memory pool. */
  245.     DB_MPOOL    *mp_info;    /* Return from memp_open(). */
  246.     size_t         mp_mmapsize;    /* Maximum file size for mmap. */
  247.     size_t         mp_size;    /* Bytes in the mpool cache. */
  248.  
  249.     /* Transactions. */
  250.     DB_TXNMGR    *tx_info;    /* Return from txn_open(). */
  251.     u_int32_t     tx_max;    /* Maximum number of transactions. */
  252.     int (*tx_recover)        /* Dispatch function for recovery. */
  253.         __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
  254.  
  255.     /*
  256.      * XA support.
  257.      *
  258.      * !!!
  259.      * Explicit representations of structures in queue.h.
  260.      *
  261.      * TAILQ_ENTRY(__db_env);
  262.      */
  263.     struct {
  264.         struct __db_env *tqe_next;
  265.         struct __db_env **tqe_prev;
  266.     } links;
  267.     int         xa_rmid;    /* XA Resource Manager ID. */
  268.     DB_TXN        *xa_txn;    /* XA Current transaction. */
  269.  
  270. #define    DB_ENV_APPINIT        0x01    /* Paths initialized by db_appinit(). */
  271. #define    DB_ENV_CDB        0x02    /* Concurrent DB product. */
  272. #define    DB_ENV_STANDALONE    0x04    /* Test: freestanding environment. */
  273. #define    DB_ENV_THREAD        0x08    /* DB_ENV is multi-threaded. */
  274.     u_int32_t     flags;        /* Flags. */
  275. };
  276.  
  277. /*******************************************************
  278.  * Access methods.
  279.  *******************************************************/
  280. /*
  281.  * !!!
  282.  * Changes here must be reflected in java/src/com/sleepycat/db/Db.java.
  283.  */
  284. typedef enum {
  285.     DB_BTREE=1,            /* B+tree. */
  286.     DB_HASH,            /* Extended Linear Hashing. */
  287.     DB_RECNO,            /* Fixed and variable-length records. */
  288.     DB_UNKNOWN            /* Figure it out on open. */
  289. } DBTYPE;
  290.  
  291. #define    DB_BTREEVERSION    6        /* Current btree version. */
  292. #define    DB_BTREEOLDVER    6        /* Oldest btree version supported. */
  293. #define    DB_BTREEMAGIC    0x053162
  294.  
  295. #define    DB_HASHVERSION    5        /* Current hash version. */
  296. #define    DB_HASHOLDVER    4        /* Oldest hash version supported. */
  297. #define    DB_HASHMAGIC    0x061561
  298.  
  299. #define    DB_LOGVERSION    2        /* Current log version. */
  300. #define    DB_LOGOLDVER    2        /* Oldest log version supported. */
  301. #define    DB_LOGMAGIC    0x040988
  302.  
  303. struct __db_info {
  304.     int         db_lorder;    /* Byte order. */
  305.     size_t         db_cachesize;    /* Underlying cache size. */
  306.     size_t         db_pagesize;    /* Underlying page size. */
  307.  
  308.                     /* Local heap allocation. */
  309.     void *(*db_malloc) __P((size_t));
  310.     int (*dup_compare)        /* Duplicate compare function. */
  311.         __P((const DBT *, const DBT *));
  312.  
  313.     /* Btree access method. */
  314.     u_int32_t     bt_maxkey;    /* Maximum keys per page. */
  315.     u_int32_t     bt_minkey;    /* Minimum keys per page. */
  316.     int (*bt_compare)        /* Comparison function. */
  317.         __P((const DBT *, const DBT *));
  318.     size_t (*bt_prefix)        /* Prefix function. */
  319.         __P((const DBT *, const DBT *));
  320.  
  321.     /* Hash access method. */
  322.     u_int32_t      h_ffactor;    /* Fill factor. */
  323.     u_int32_t     h_nelem;    /* Number of elements. */
  324.     u_int32_t      (*h_hash)    /* Hash function. */
  325.         __P((const void *, u_int32_t));
  326.  
  327.     /* Recno access method. */
  328.     int         re_pad;    /* Fixed-length padding byte. */
  329.     int         re_delim;    /* Variable-length delimiting byte. */
  330.     u_int32_t     re_len;    /* Length for fixed-length records. */
  331.     char        *re_source;    /* Source file name. */
  332.  
  333. #define    DB_DELIMITER        0x0001    /* Recno: re_delim set. */
  334. #define    DB_DUP            0x0002    /* Btree, Hash: duplicate keys. */
  335. #define    DB_DUPSORT        0x0004    /* Btree, Hash: duplicate keys. */
  336. #define    DB_FIXEDLEN        0x0008    /* Recno: fixed-length records. */
  337. #define    DB_PAD            0x0010    /* Recno: re_pad set. */
  338. #define    DB_RECNUM        0x0020    /* Btree: record numbers. */
  339. #define    DB_RENUMBER        0x0040    /* Recno: renumber on insert/delete. */
  340. #define    DB_SNAPSHOT        0x0080    /* Recno: snapshot the input. */
  341.     u_int32_t     flags;
  342. };
  343.  
  344. /*
  345.  * DB access method and cursor operation values.  Each value is an operation
  346.  * code to which additional bit flags are added.
  347.  */
  348. #define    DB_AFTER     1        /* c_put() */
  349. #define    DB_APPEND     2        /* put() */
  350. #define    DB_BEFORE     3        /* c_put() */
  351. #define    DB_CHECKPOINT     4        /* log_put(), log_get() */
  352. #define    DB_CURLSN     5        /* log_put() */
  353. #define    DB_CURRENT     6        /* c_get(), c_put(), log_get() */
  354. #define    DB_FIRST     7        /* c_get(), log_get() */
  355. #define    DB_FLUSH     8        /* log_put() */
  356. #define    DB_GET_BOTH     9        /* get(), c_get() */
  357. #define    DB_GET_RECNO    10        /* c_get() */
  358. #define    DB_JOIN_ITEM    11        /* c_get(); do not do primary lookup */
  359. #define    DB_KEYFIRST    12        /* c_put() */
  360. #define    DB_KEYLAST    13        /* c_put() */
  361. #define    DB_LAST        14        /* c_get(), log_get() */
  362. #define    DB_NEXT        15        /* c_get(), log_get() */
  363. #define    DB_NEXT_DUP    16        /* c_get() */
  364. #define    DB_NOOVERWRITE    17        /* put() */
  365. #define    DB_NOSYNC    18        /* close() */
  366. #define    DB_PREV        19        /* c_get(), log_get() */
  367. #define    DB_RECORDCOUNT    20        /* stat() */
  368. #define    DB_SET        21        /* c_get(), log_get() */
  369. #define    DB_SET_RANGE    22        /* c_get() */
  370. #define    DB_SET_RECNO    23        /* get(), c_get() */
  371. #define    DB_WRITELOCK    24        /* cursor() (internal) */
  372.  
  373. #define    DB_OPFLAGS_MASK    0x1f        /* Mask for operations flags. */
  374. #define    DB_RMW        0x80000000    /* Acquire write flag immediately. */
  375.  
  376. /*
  377.  * DB (user visible) error return codes.
  378.  *
  379.  * !!!
  380.  * Changes to any of the user visible error return codes must be reflected
  381.  * in java/src/com/sleepycat/db/Db.java.
  382.  */
  383. #define    DB_INCOMPLETE        ( -1)    /* Sync didn't finish. */
  384. #define    DB_KEYEMPTY        ( -2)    /* The key/data pair was deleted or
  385.                        was never created by the user. */
  386. #define    DB_KEYEXIST        ( -3)    /* The key/data pair already exists. */
  387. #define    DB_LOCK_DEADLOCK    ( -4)    /* Locker killed to resolve deadlock. */
  388. #define    DB_LOCK_NOTGRANTED    ( -5)    /* Lock unavailable, no-wait set. */
  389. #define    DB_LOCK_NOTHELD        ( -6)    /* Lock not held by locker. */
  390. #define    DB_NOTFOUND        ( -7)    /* Key/data pair not found (EOF). */
  391. #define    DB_RUNRECOVERY        ( -8)    /* Panic return. */
  392.  
  393. /* DB (private) error return codes. */
  394. #define    DB_DELETED        ( -9)    /* Recovery file marked deleted. */
  395. #define    DB_NEEDSPLIT        (-10)    /* Page needs to be split. */
  396. #define    DB_SWAPBYTES        (-11)    /* Database needs byte swapping. */
  397. #define    DB_TXN_CKP        (-12)    /* Encountered ckp record in log. */
  398.  
  399. #define    DB_FILE_ID_LEN        20    /* DB file ID length. */
  400.  
  401. /* DB access method description structure. */
  402. struct __db {
  403.     void    *mutexp;        /* Synchronization for free threading */
  404.  
  405.                     /* Documented, returned information. */
  406.     DBTYPE     type;            /* DB access method. */
  407.     int     byteswapped;        /* Database byte order is swapped. */
  408.  
  409.     DB_ENV    *dbenv;            /* DB_ENV structure. */
  410.     DB_ENV    *mp_dbenv;        /* DB_ENV for local mpool creation. */
  411.  
  412.     void    *internal;        /* Access method private. */
  413.  
  414.     DB_MPOOL    *mp;        /* The access method's mpool. */
  415.     DB_MPOOLFILE    *mpf;        /* The access method's mpool file. */
  416.  
  417.     /*
  418.      * !!!
  419.      * Explicit representations of structures in queue.h.
  420.      *
  421.      * TAILQ_HEAD(free_queue, __dbc);
  422.      * TAILQ_HEAD(active_queue, __dbc);
  423.      */
  424.     struct {
  425.         struct __dbc *tqh_first;
  426.         struct __dbc **tqh_last;
  427.     } free_queue;
  428.     struct {
  429.         struct __dbc *tqh_first;
  430.         struct __dbc **tqh_last;
  431.     } active_queue;
  432.  
  433.     u_int8_t  fileid[DB_FILE_ID_LEN]; /* Uniquely identify this file for
  434.                          locking. */
  435.     u_int32_t log_fileid;        /* Logging file id. */
  436.     size_t      pgsize;        /* Logical page size of file. */
  437.  
  438.                     /* Local heap allocation. */
  439.     void *(*db_malloc) __P((size_t));
  440.     int (*dup_compare)        /* Duplicate compare function. */
  441.         __P((const DBT *, const DBT *));
  442.     u_int32_t (*h_hash)        /* Hash function. */
  443.         __P((const void *, u_int32_t));
  444.  
  445.                     /* Functions. */
  446.     int (*am_close)    __P((DB *));
  447.     int (*close)    __P((DB *, u_int32_t));
  448.     int (*cursor)    __P((DB *, DB_TXN *, DBC **, u_int32_t));
  449.     int (*del)    __P((DB *, DB_TXN *, DBT *, u_int32_t));
  450.     int (*fd)    __P((DB *, int *));
  451.     int (*get)    __P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t));
  452.     int (*join)    __P((DB *, DBC **, u_int32_t, DBC **));
  453.     int (*put)    __P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t));
  454.     int (*stat)    __P((DB *, void *, void *(*)(size_t), u_int32_t));
  455.     int (*sync)    __P((DB *, u_int32_t));
  456.  
  457. #define    DB_AM_CDB    0x000001    /* Concurrent Access Methods. */
  458. #define    DB_AM_DUP    0x000002    /* DB_DUP (internal). */
  459. #define    DB_AM_INMEM    0x000004    /* In-memory; no sync on close. */
  460. #define    DB_AM_LOCKING    0x000008    /* Perform locking. */
  461. #define    DB_AM_LOGGING    0x000010    /* Perform logging. */
  462. #define    DB_AM_MLOCAL    0x000020    /* Database memory pool is local. */
  463. #define    DB_AM_PGDEF    0x000040    /* Page size was defaulted. */
  464. #define    DB_AM_RDONLY    0x000080    /* Database is readonly. */
  465. #define    DB_AM_SWAP    0x000100    /* Pages need to be byte-swapped. */
  466. #define    DB_AM_THREAD    0x000200    /* DB is multi-threaded. */
  467. #define    DB_BT_RECNUM    0x000400    /* DB_RECNUM (internal). */
  468. #define    DB_DBM_ERROR    0x000800    /* Error in DBM/NDBM database. */
  469. #define    DB_RE_DELIMITER    0x001000    /* DB_DELIMITER (internal). */
  470. #define    DB_RE_FIXEDLEN    0x002000    /* DB_FIXEDLEN (internal). */
  471. #define    DB_RE_PAD    0x004000    /* DB_PAD (internal). */
  472. #define    DB_RE_RENUMBER    0x008000    /* DB_RENUMBER (internal). */
  473. #define    DB_RE_SNAPSHOT    0x010000    /* DB_SNAPSHOT (internal). */
  474.     u_int32_t flags;
  475. };
  476.  
  477. struct __db_ilock {            /* Internal DB access method lock. */
  478.     db_pgno_t pgno;            /* Page being locked. */
  479.     u_int8_t fileid[DB_FILE_ID_LEN];/* File id. */
  480. };
  481.  
  482. /* Cursor description structure. */
  483. struct __dbc {
  484.     DB *dbp;            /* Related DB access method. */
  485.     DB_TXN     *txn;            /* Associated transaction. */
  486.  
  487.     /*
  488.      * !!!
  489.      * Explicit representations of structures in queue.h.
  490.      *
  491.      * TAILQ_ENTRY(__dbc);
  492.      */
  493.     struct {
  494.         struct __dbc *tqe_next;
  495.         struct __dbc **tqe_prev;
  496.     } links;
  497.  
  498.     u_int32_t lid;            /* Default process' locker id. */
  499.     u_int32_t locker;        /* Locker for this operation. */
  500.     DBT      lock_dbt;        /* DBT referencing lock. */
  501.     DB_LOCK_ILOCK lock;        /* Object to be locked. */
  502.     DB_LOCK    mylock;            /* Lock held on this cursor. */
  503.  
  504.     DBT rkey;            /* Returned key. */
  505.     DBT rdata;            /* Returned data. */
  506.  
  507.     int (*c_am_close) __P((DBC *));
  508.     int (*c_am_destroy) __P((DBC *));
  509.     int (*c_close) __P((DBC *));
  510.     int (*c_del) __P((DBC *, u_int32_t));
  511.     int (*c_get) __P((DBC *, DBT *, DBT *, u_int32_t));
  512.     int (*c_put) __P((DBC *, DBT *, DBT *, u_int32_t));
  513.  
  514.     void     *internal;        /* Access method private. */
  515.  
  516. #define    DBC_CONTINUE    0x001        /* Continue dup search: next item. */
  517. #define    DBC_KEYSET    0x002        /* Continue dup search: current item. */
  518. #define    DBC_RECOVER    0x004        /* In recovery (do not log or lock). */
  519. #define    DBC_RMW        0x008        /* Acquire write flag in read op. */
  520. #define    DBC_WRITER    0x010        /* Cursor immediately writing (CDB). */
  521.     u_int32_t flags;
  522. };
  523.  
  524. /* Btree/recno statistics structure. */
  525. struct __db_bt_stat {
  526.     u_int32_t bt_flags;        /* Open flags. */
  527.     u_int32_t bt_maxkey;        /* Maxkey value. */
  528.     u_int32_t bt_minkey;        /* Minkey value. */
  529.     u_int32_t bt_re_len;        /* Fixed-length record length. */
  530.     u_int32_t bt_re_pad;        /* Fixed-length record pad. */
  531.     u_int32_t bt_pagesize;        /* Page size. */
  532.     u_int32_t bt_levels;        /* Tree levels. */
  533.     u_int32_t bt_nrecs;        /* Number of records. */
  534.     u_int32_t bt_int_pg;        /* Internal pages. */
  535.     u_int32_t bt_leaf_pg;        /* Leaf pages. */
  536.     u_int32_t bt_dup_pg;        /* Duplicate pages. */
  537.     u_int32_t bt_over_pg;        /* Overflow pages. */
  538.     u_int32_t bt_free;        /* Pages on the free list. */
  539.     u_int32_t bt_int_pgfree;    /* Bytes free in internal pages. */
  540.     u_int32_t bt_leaf_pgfree;    /* Bytes free in leaf pages. */
  541.     u_int32_t bt_dup_pgfree;    /* Bytes free in duplicate pages. */
  542.     u_int32_t bt_over_pgfree;    /* Bytes free in overflow pages. */
  543.     u_int32_t bt_magic;        /* Magic number. */
  544.     u_int32_t bt_version;        /* Version number. */
  545. };
  546.  
  547. /* Hash statistics structure. */
  548. struct __db_h_stat {
  549.     u_int32_t hash_accesses;    /* Number of accesses to this table. */
  550.     u_int32_t hash_collisions;    /* Number of collisions on search. */
  551.     u_int32_t hash_expansions;    /* Number of times we added a bucket. */
  552.     u_int32_t hash_overflows;    /* Number of overflow pages. */
  553.     u_int32_t hash_bigpages;    /* Number of big key/data pages. */
  554.     u_int32_t hash_dup;        /* Number of dup pages. */
  555.     u_int32_t hash_free;        /* Pages on the free list. */
  556.     u_int32_t hash_bfree;        /* Bytes free on bucket pages. */
  557.     u_int32_t hash_dup_free;    /* Bytes free on duplicate pages. */
  558.     u_int32_t hash_big_bfree;    /* Bytes free on big item pages. */
  559.     u_int32_t hash_buckets;        /* Number of hash buckets. */
  560.     u_int32_t hash_put;        /* Number of puts. */
  561.     u_int32_t hash_deleted;        /* Number of deletes. */
  562.     u_int32_t hash_get;        /* Number of gets. */
  563.     u_int32_t hash_magic;        /* Magic number. */
  564.     u_int32_t hash_version;        /* Version number. */
  565.     u_int32_t hash_pagesize;    /* Page size. */
  566.     u_int32_t hash_nrecs;        /* Number of records. */
  567. };
  568.  
  569. #if defined(__cplusplus)
  570. extern "C" {
  571. #endif
  572. int   db_appinit __P((const char *, char * const *, DB_ENV *, u_int32_t));
  573. int   db_appexit __P((DB_ENV *));
  574. int   db_jump_set __P((void *, int));
  575. int   db_open __P((const char *,
  576.       DBTYPE, u_int32_t, int, DB_ENV *, DB_INFO *, DB **));
  577. int   db_value_set __P((int, int));
  578. char *db_version __P((int *, int *, int *));
  579. int   db_xa_open __P((const char *,
  580.       DBTYPE, u_int32_t, int, DB_INFO *, DB **));
  581. #if defined(__cplusplus)
  582. }
  583. #endif
  584.  
  585. /*******************************************************
  586.  * Locking
  587.  *******************************************************/
  588. #define    DB_LOCKVERSION    1
  589. #define    DB_LOCKMAGIC    0x090193
  590.  
  591. /* Flag values for lock_vec(), lock_get(). */
  592. #define    DB_LOCK_NOWAIT        0x01    /* Don't wait on unavailable lock. */
  593. #define    DB_LOCK_UPGRADE        0x02    /* Upgrade an existing lock instead
  594.                        of granting a new one (internal). */
  595.  
  596. /* Flag values for lock_detect(). */
  597. #define    DB_LOCK_CONFLICT    0x01    /* Run on any conflict. */
  598.  
  599. /*
  600.  * Request types.
  601.  *
  602.  * !!!
  603.  * Changes here must be reflected in java/src/com/sleepycat/db/Db.java.
  604.  */
  605. typedef enum {
  606.     DB_LOCK_DUMP=0,            /* Display held locks. */
  607.     DB_LOCK_GET,            /* Get the lock. */
  608.     DB_LOCK_INHERIT,        /* Pass locks to parent. */
  609.     DB_LOCK_PUT,            /* Release the lock. */
  610.     DB_LOCK_PUT_ALL,        /* Release locker's locks. */
  611.     DB_LOCK_PUT_OBJ            /* Release locker's locks on obj. */
  612. } db_lockop_t;
  613.  
  614. /*
  615.  * Simple R/W lock modes and for multi-granularity intention locking.
  616.  *
  617.  * !!!
  618.  * These values are NOT random, as they are used as an index into the lock
  619.  * conflicts arrays, i.e., DB_LOCK_IWRITE must be == 3, and DB_LOCK_IREAD
  620.  * must be == 4.
  621.  *
  622.  * !!!
  623.  * Changes here must be reflected in java/src/com/sleepycat/db/Db.java.
  624.  */
  625. typedef enum {
  626.     DB_LOCK_NG=0,            /* Not granted. */
  627.     DB_LOCK_READ,            /* Shared/read. */
  628.     DB_LOCK_WRITE,            /* Exclusive/write. */
  629.     DB_LOCK_IWRITE,            /* Intent exclusive/write. */
  630.     DB_LOCK_IREAD,            /* Intent to share/read. */
  631.     DB_LOCK_IWR            /* Intent to read and write. */
  632. } db_lockmode_t;
  633.  
  634. /*
  635.  * Status of a lock.
  636.  */
  637. typedef enum {
  638.     DB_LSTAT_ABORTED,        /* Lock belongs to an aborted txn. */
  639.     DB_LSTAT_ERR,            /* Lock is bad. */
  640.     DB_LSTAT_FREE,            /* Lock is unallocated. */
  641.     DB_LSTAT_HELD,            /* Lock is currently held. */
  642.     DB_LSTAT_NOGRANT,        /* Lock was not granted. */
  643.     DB_LSTAT_PENDING,        /* Lock was waiting and has been
  644.                      * promoted; waiting for the owner
  645.                      * to run and upgrade it to held. */
  646.     DB_LSTAT_WAITING        /* Lock is on the wait queue. */
  647. } db_status_t;
  648.  
  649. /* Lock request structure. */
  650. struct __db_lockreq {
  651.     db_lockop_t     op;        /* Operation. */
  652.     db_lockmode_t     mode;        /* Requested mode. */
  653.     u_int32_t     locker;    /* Locker identity. */
  654.     DBT        *obj;        /* Object being locked. */
  655.     DB_LOCK         lock;        /* Lock returned. */
  656. };
  657.  
  658. /*
  659.  * Commonly used conflict matrices.
  660.  *
  661.  * Standard Read/Write (or exclusive/shared) locks.
  662.  */
  663. #define    DB_LOCK_RW_N    3
  664. extern const u_int8_t db_rw_conflicts[];
  665.  
  666. /* Multi-granularity locking. */
  667. #define    DB_LOCK_RIW_N    6
  668. extern const u_int8_t db_riw_conflicts[];
  669.  
  670. struct __db_lock_stat {
  671.     u_int32_t st_magic;        /* Lock file magic number. */
  672.     u_int32_t st_version;        /* Lock file version number. */
  673.     u_int32_t st_maxlocks;        /* Maximum number of locks in table. */
  674.     u_int32_t st_nmodes;        /* Number of lock modes. */
  675.     u_int32_t st_numobjs;        /* Number of objects. */
  676.     u_int32_t st_nlockers;        /* Number of lockers. */
  677.     u_int32_t st_nconflicts;    /* Number of lock conflicts. */
  678.     u_int32_t st_nrequests;        /* Number of lock gets. */
  679.     u_int32_t st_nreleases;        /* Number of lock puts. */
  680.     u_int32_t st_ndeadlocks;    /* Number of lock deadlocks. */
  681.     u_int32_t st_region_wait;    /* Region lock granted after wait. */
  682.     u_int32_t st_region_nowait;    /* Region lock granted without wait. */
  683.     u_int32_t st_refcnt;        /* Region reference count. */
  684.     u_int32_t st_regsize;        /* Region size. */
  685. };
  686.  
  687. #if defined(__cplusplus)
  688. extern "C" {
  689. #endif
  690. int      lock_close __P((DB_LOCKTAB *));
  691. int      lock_detect __P((DB_LOCKTAB *, u_int32_t, u_int32_t));
  692. int      lock_get __P((DB_LOCKTAB *,
  693.         u_int32_t, u_int32_t, const DBT *, db_lockmode_t, DB_LOCK *));
  694. int      lock_id __P((DB_LOCKTAB *, u_int32_t *));
  695. int      lock_open __P((const char *,
  696.         u_int32_t, int, DB_ENV *, DB_LOCKTAB **));
  697. int      lock_put __P((DB_LOCKTAB *, DB_LOCK));
  698. int      lock_tget __P((DB_LOCKTAB *,
  699.         DB_TXN *, u_int32_t, const DBT *, db_lockmode_t, DB_LOCK *));
  700. int      lock_stat __P((DB_LOCKTAB *, DB_LOCK_STAT **, void *(*)(size_t)));
  701. int      lock_unlink __P((const char *, int, DB_ENV *));
  702. int      lock_vec __P((DB_LOCKTAB *,
  703.         u_int32_t, u_int32_t, DB_LOCKREQ *, int, DB_LOCKREQ **));
  704. int      lock_tvec __P((DB_LOCKTAB *,
  705.         DB_TXN *, u_int32_t, DB_LOCKREQ *, int, DB_LOCKREQ **));
  706. #if defined(__cplusplus)
  707. }
  708. #endif
  709.  
  710. /*******************************************************
  711.  * Logging.
  712.  *******************************************************/
  713. /* Flag values for log_archive(). */
  714. #define    DB_ARCH_ABS        0x001    /* Absolute pathnames. */
  715. #define    DB_ARCH_DATA        0x002    /* Data files. */
  716. #define    DB_ARCH_LOG        0x004    /* Log files. */
  717.  
  718. /*
  719.  * A DB_LSN has two parts, a fileid which identifies a specific file, and an
  720.  * offset within that file.  The fileid is an unsigned 4-byte quantity that
  721.  * uniquely identifies a file within the log directory -- currently a simple
  722.  * counter inside the log.  The offset is also an unsigned 4-byte value.  The
  723.  * log manager guarantees the offset is never more than 4 bytes by switching
  724.  * to a new log file before the maximum length imposed by an unsigned 4-byte
  725.  * offset is reached.
  726.  */
  727. struct __db_lsn {
  728.     u_int32_t    file;        /* File ID. */
  729.     u_int32_t    offset;        /* File offset. */
  730. };
  731.  
  732. /* Log statistics structure. */
  733. struct __db_log_stat {
  734.     u_int32_t st_magic;        /* Log file magic number. */
  735.     u_int32_t st_version;        /* Log file version number. */
  736.     int st_mode;            /* Log file mode. */
  737.     u_int32_t st_lg_max;        /* Maximum log file size. */
  738.     u_int32_t st_w_bytes;        /* Bytes to log. */
  739.     u_int32_t st_w_mbytes;        /* Megabytes to log. */
  740.     u_int32_t st_wc_bytes;        /* Bytes to log since checkpoint. */
  741.     u_int32_t st_wc_mbytes;        /* Megabytes to log since checkpoint. */
  742.     u_int32_t st_wcount;        /* Total syncs to the log. */
  743.     u_int32_t st_scount;        /* Total writes to the log. */
  744.     u_int32_t st_region_wait;    /* Region lock granted after wait. */
  745.     u_int32_t st_region_nowait;    /* Region lock granted without wait. */
  746.     u_int32_t st_cur_file;        /* Current log file number. */
  747.     u_int32_t st_cur_offset;    /* Current log file offset. */
  748.     u_int32_t st_refcnt;        /* Region reference count. */
  749.     u_int32_t st_regsize;        /* Region size. */
  750. };
  751.  
  752. #if defined(__cplusplus)
  753. extern "C" {
  754. #endif
  755. int     log_archive __P((DB_LOG *, char **[], u_int32_t, void *(*)(size_t)));
  756. int     log_close __P((DB_LOG *));
  757. int     log_compare __P((const DB_LSN *, const DB_LSN *));
  758. int     log_file __P((DB_LOG *, const DB_LSN *, char *, size_t));
  759. int     log_flush __P((DB_LOG *, const DB_LSN *));
  760. int     log_get __P((DB_LOG *, DB_LSN *, DBT *, u_int32_t));
  761. int     log_open __P((const char *, u_int32_t, int, DB_ENV *, DB_LOG **));
  762. int     log_put __P((DB_LOG *, DB_LSN *, const DBT *, u_int32_t));
  763. int     log_register __P((DB_LOG *, DB *, const char *, DBTYPE, u_int32_t *));
  764. int     log_stat __P((DB_LOG *, DB_LOG_STAT **, void *(*)(size_t)));
  765. int     log_unlink __P((const char *, int, DB_ENV *));
  766. int     log_unregister __P((DB_LOG *, u_int32_t));
  767. #if defined(__cplusplus)
  768. }
  769. #endif
  770.  
  771. /*******************************************************
  772.  * Mpool
  773.  *******************************************************/
  774. /* Flag values for memp_fget(). */
  775. #define    DB_MPOOL_CREATE        0x001    /* Create a page. */
  776. #define    DB_MPOOL_LAST        0x002    /* Return the last page. */
  777. #define    DB_MPOOL_NEW        0x004    /* Create a new page. */
  778.  
  779. /* Flag values for memp_fput(), memp_fset(). */
  780. #define    DB_MPOOL_CLEAN        0x001    /* Clear modified bit. */
  781. #define    DB_MPOOL_DIRTY        0x002    /* Page is modified. */
  782. #define    DB_MPOOL_DISCARD    0x004    /* Don't cache the page. */
  783.  
  784. /* Mpool statistics structure. */
  785. struct __db_mpool_stat {
  786.     size_t st_cachesize;        /* Cache size. */
  787.     u_int32_t st_cache_hit;        /* Pages found in the cache. */
  788.     u_int32_t st_cache_miss;    /* Pages not found in the cache. */
  789.     u_int32_t st_map;        /* Pages from mapped files. */
  790.     u_int32_t st_page_create;    /* Pages created in the cache. */
  791.     u_int32_t st_page_in;        /* Pages read in. */
  792.     u_int32_t st_page_out;        /* Pages written out. */
  793.     u_int32_t st_ro_evict;        /* Clean pages forced from the cache. */
  794.     u_int32_t st_rw_evict;        /* Dirty pages forced from the cache. */
  795.     u_int32_t st_hash_buckets;    /* Number of hash buckets. */
  796.     u_int32_t st_hash_searches;    /* Total hash chain searches. */
  797.     u_int32_t st_hash_longest;    /* Longest hash chain searched. */
  798.     u_int32_t st_hash_examined;    /* Total hash entries searched. */
  799.     u_int32_t st_page_clean;    /* Clean pages. */
  800.     u_int32_t st_page_dirty;    /* Dirty pages. */
  801.     u_int32_t st_page_trickle;    /* Pages written by memp_trickle. */
  802.     u_int32_t st_region_wait;    /* Region lock granted after wait. */
  803.     u_int32_t st_region_nowait;    /* Region lock granted without wait. */
  804.     u_int32_t st_refcnt;        /* Region reference count. */
  805.     u_int32_t st_regsize;        /* Region size. */
  806. };
  807.  
  808. /* Mpool file open information structure. */
  809. struct __db_mpool_finfo {
  810.     int       ftype;        /* File type. */
  811.     DBT      *pgcookie;        /* Byte-string passed to pgin/pgout. */
  812.     u_int8_t  *fileid;        /* Unique file ID. */
  813.     int32_t       lsn_offset;        /* LSN offset in page. */
  814.     u_int32_t  clear_len;        /* Cleared length on created pages. */
  815. };
  816.  
  817. /* Mpool file statistics structure. */
  818. struct __db_mpool_fstat {
  819.     char *file_name;        /* File name. */
  820.     size_t st_pagesize;        /* Page size. */
  821.     u_int32_t st_cache_hit;        /* Pages found in the cache. */
  822.     u_int32_t st_cache_miss;    /* Pages not found in the cache. */
  823.     u_int32_t st_map;        /* Pages from mapped files. */
  824.     u_int32_t st_page_create;    /* Pages created in the cache. */
  825.     u_int32_t st_page_in;        /* Pages read in. */
  826.     u_int32_t st_page_out;        /* Pages written out. */
  827. };
  828.  
  829. #if defined(__cplusplus)
  830. extern "C" {
  831. #endif
  832. int    memp_close __P((DB_MPOOL *));
  833. int    memp_fclose __P((DB_MPOOLFILE *));
  834. int    memp_fget __P((DB_MPOOLFILE *, db_pgno_t *, u_int32_t, void *));
  835. int    memp_fopen __P((DB_MPOOL *, const char *,
  836.         u_int32_t, int, size_t, DB_MPOOL_FINFO *, DB_MPOOLFILE **));
  837. int    memp_fput __P((DB_MPOOLFILE *, void *, u_int32_t));
  838. int    memp_fset __P((DB_MPOOLFILE *, void *, u_int32_t));
  839. int    memp_fsync __P((DB_MPOOLFILE *));
  840. int    memp_open __P((const char *, u_int32_t, int, DB_ENV *, DB_MPOOL **));
  841. int    memp_register __P((DB_MPOOL *, int,
  842.         int (*)(db_pgno_t, void *, DBT *),
  843.         int (*)(db_pgno_t, void *, DBT *)));
  844. int    memp_stat __P((DB_MPOOL *,
  845.         DB_MPOOL_STAT **, DB_MPOOL_FSTAT ***, void *(*)(size_t)));
  846. int    memp_sync __P((DB_MPOOL *, DB_LSN *));
  847. int    memp_trickle __P((DB_MPOOL *, int, int *));
  848. int    memp_unlink __P((const char *, int, DB_ENV *));
  849. #if defined(__cplusplus)
  850. }
  851. #endif
  852.  
  853. /*******************************************************
  854.  * Transactions.
  855.  *******************************************************/
  856. #define    DB_TXNVERSION    1
  857. #define    DB_TXNMAGIC    0x041593
  858.  
  859. /* Operations values to the tx_recover() function. */
  860. #define    DB_TXN_BACKWARD_ROLL    1    /* Read the log backwards. */
  861. #define    DB_TXN_FORWARD_ROLL    2    /* Read the log forwards. */
  862. #define    DB_TXN_OPENFILES    3    /* Read for open files. */
  863. #define    DB_TXN_REDO        4    /* Redo the operation. */
  864. #define    DB_TXN_UNDO        5    /* Undo the operation. */
  865.  
  866. /* Internal transaction status values. */
  867.  
  868. /* Transaction statistics structure. */
  869. struct __db_txn_active {
  870.     u_int32_t    txnid;        /* Transaction ID */
  871.     DB_LSN        lsn;        /* Lsn of the begin record */
  872. };
  873.  
  874. struct __db_txn_stat {
  875.     DB_LSN      st_last_ckp;        /* lsn of the last checkpoint */
  876.     DB_LSN      st_pending_ckp;    /* last checkpoint did not finish */
  877.     time_t      st_time_ckp;        /* time of last checkpoint */
  878.     u_int32_t st_last_txnid;    /* last transaction id given out */
  879.     u_int32_t st_maxtxns;    /* maximum number of active txns */
  880.     u_int32_t st_naborts;    /* number of aborted transactions */
  881.     u_int32_t st_nbegins;    /* number of begun transactions */
  882.     u_int32_t st_ncommits;    /* number of committed transactions */
  883.     u_int32_t st_nactive;    /* number of active transactions */
  884.     DB_TXN_ACTIVE
  885.          *st_txnarray;    /* array of active transactions */
  886.     u_int32_t st_region_wait;    /* Region lock granted after wait. */
  887.     u_int32_t st_region_nowait;    /* Region lock granted without wait. */
  888.     u_int32_t st_refcnt;        /* Region reference count. */
  889.     u_int32_t st_regsize;        /* Region size. */
  890. };
  891.  
  892. #if defined(__cplusplus)
  893. extern "C" {
  894. #endif
  895. int      txn_abort __P((DB_TXN *));
  896. int      txn_begin __P((DB_TXNMGR *, DB_TXN *, DB_TXN **));
  897. int      txn_checkpoint __P((const DB_TXNMGR *, u_int32_t, u_int32_t));
  898. int      txn_commit __P((DB_TXN *));
  899. int      txn_close __P((DB_TXNMGR *));
  900. u_int32_t txn_id __P((DB_TXN *));
  901. int      txn_open __P((const char *, u_int32_t, int, DB_ENV *, DB_TXNMGR **));
  902. int      txn_prepare __P((DB_TXN *));
  903. int      txn_stat __P((DB_TXNMGR *, DB_TXN_STAT **, void *(*)(size_t)));
  904. int      txn_unlink __P((const char *, int, DB_ENV *));
  905. #if defined(__cplusplus)
  906. }
  907. #endif
  908.  
  909. #ifndef DB_DBM_HSEARCH
  910. #define    DB_DBM_HSEARCH    0        /* No historic interfaces by default. */
  911. #endif
  912. #if DB_DBM_HSEARCH != 0
  913. /*******************************************************
  914.  * Dbm/Ndbm historic interfaces.
  915.  *******************************************************/
  916. #define    DBM_INSERT    0        /* Flags to dbm_store(). */
  917. #define    DBM_REPLACE    1
  918.  
  919. /*
  920.  * The db(3) support for ndbm(3) always appends this suffix to the
  921.  * file name to avoid overwriting the user's original database.
  922.  */
  923. #define    DBM_SUFFIX    ".db"
  924.  
  925. #if defined(_XPG4_2)
  926. typedef struct {
  927.     char *dptr;
  928.     size_t dsize;
  929. } datum;
  930. #else
  931. typedef struct {
  932.     char *dptr;
  933.     int dsize;
  934. } datum;
  935. #endif
  936.  
  937. /*
  938.  * Translate DBM calls into DB calls so that DB doesn't step on the
  939.  * application's name space.
  940.  *
  941.  * The global variables dbrdonly, dirf and pagf were not retained when
  942.  * 4BSD replaced the dbm interface with ndbm, and are not support here.
  943.  */
  944. #define    dbminit(a)    __db_dbm_init(a)
  945. #define    dbmclose    __db_dbm_close
  946. #if !defined(__cplusplus)
  947. #define    delete(a)    __db_dbm_delete(a)
  948. #endif
  949. #define    fetch(a)    __db_dbm_fetch(a)
  950. #define    firstkey    __db_dbm_firstkey
  951. #define    nextkey(a)    __db_dbm_nextkey(a)
  952. #define    store(a, b)    __db_dbm_store(a, b)
  953.  
  954. /* Prototype the DB calls. */
  955. #if defined(__cplusplus)
  956. extern "C" {
  957. #endif
  958. int     __db_dbm_close __P((void));
  959. int     __db_dbm_dbrdonly __P((void));
  960. int     __db_dbm_delete __P((datum));
  961. int     __db_dbm_dirf __P((void));
  962. datum     __db_dbm_fetch __P((datum));
  963. datum     __db_dbm_firstkey __P((void));
  964. int     __db_dbm_init __P((char *));
  965. datum     __db_dbm_nextkey __P((datum));
  966. int     __db_dbm_pagf __P((void));
  967. int     __db_dbm_store __P((datum, datum));
  968. #if defined(__cplusplus)
  969. }
  970. #endif
  971.  
  972. /*
  973.  * Translate NDBM calls into DB calls so that DB doesn't step on the
  974.  * application's name space.
  975.  */
  976. #define    dbm_clearerr(a)        __db_ndbm_clearerr(a)
  977. #define    dbm_close(a)        __db_ndbm_close(a)
  978. #define    dbm_delete(a, b)    __db_ndbm_delete(a, b)
  979. #define    dbm_dirfno(a)        __db_ndbm_dirfno(a)
  980. #define    dbm_error(a)        __db_ndbm_error(a)
  981. #define    dbm_fetch(a, b)        __db_ndbm_fetch(a, b)
  982. #define    dbm_firstkey(a)        __db_ndbm_firstkey(a)
  983. #define    dbm_nextkey(a)        __db_ndbm_nextkey(a)
  984. #define    dbm_open(a, b, c)    __db_ndbm_open(a, b, c)
  985. #define    dbm_pagfno(a)        __db_ndbm_pagfno(a)
  986. #define    dbm_rdonly(a)        __db_ndbm_rdonly(a)
  987. #define    dbm_store(a, b, c, d)    __db_ndbm_store(a, b, c, d)
  988.  
  989. /* Prototype the DB calls. */
  990. #if defined(__cplusplus)
  991. extern "C" {
  992. #endif
  993. int     __db_ndbm_clearerr __P((DBM *));
  994. void     __db_ndbm_close __P((DBM *));
  995. int     __db_ndbm_delete __P((DBM *, datum));
  996. int     __db_ndbm_dirfno __P((DBM *));
  997. int     __db_ndbm_error __P((DBM *));
  998. datum     __db_ndbm_fetch __P((DBM *, datum));
  999. datum     __db_ndbm_firstkey __P((DBM *));
  1000. datum     __db_ndbm_nextkey __P((DBM *));
  1001. DBM    *__db_ndbm_open __P((const char *, int, int));
  1002. int     __db_ndbm_pagfno __P((DBM *));
  1003. int     __db_ndbm_rdonly __P((DBM *));
  1004. int     __db_ndbm_store __P((DBM *, datum, datum, int));
  1005. #if defined(__cplusplus)
  1006. }
  1007. #endif
  1008.  
  1009. /*******************************************************
  1010.  * Hsearch historic interface.
  1011.  *******************************************************/
  1012. typedef enum {
  1013.     FIND, ENTER
  1014. } ACTION;
  1015.  
  1016. typedef struct entry {
  1017.     char *key;
  1018.     char *data;
  1019. } ENTRY;
  1020.  
  1021. /*
  1022.  * Translate HSEARCH calls into DB calls so that DB doesn't step on the
  1023.  * application's name space.
  1024.  */
  1025. #define    hcreate(a)    __db_hcreate(a)
  1026. #define    hdestroy    __db_hdestroy
  1027. #define    hsearch(a, b)    __db_hsearch(a, b)
  1028.  
  1029. /* Prototype the DB calls. */
  1030. #if defined(__cplusplus)
  1031. extern "C" {
  1032. #endif
  1033. int     __db_hcreate __P((size_t));
  1034. void     __db_hdestroy __P((void));
  1035. ENTRY    *__db_hsearch __P((ENTRY, ACTION));
  1036. #if defined(__cplusplus)
  1037. }
  1038. #endif
  1039. #endif /* DB_DBM_HSEARCH */
  1040.  
  1041. /*
  1042.  * XXX
  1043.  * MacOS: Reset Metrowerks C enum sizes.
  1044.  */
  1045. #ifdef __MWERKS__
  1046. #pragma enumsalwaysint reset
  1047. #endif
  1048. #endif /* !_DB_H_ */
  1049.